//
//  UIView+HUD.m
//  JYFarm
//
//  Created by 花花 on 2017/11/5.
//  Copyright © 2017年 花花. All rights reserved.
//

#import "UIView+HUD.h"
#import <MBProgressHUD.h>
@implementation UIView (HUD)
/**
 提示语显示后会自动消失
 
 @param tips 提示内容
 */
- (void)showTipAutoDisappear:(NSString *)tips{

    
    [self showTips:tips AutoHideAfterTimer:1];
}


/**
 提示语显示后要指定时间才会消失
 
 @param tips 提示的内容
 @param showTime 显示时间
 */
- (void)showTips:(NSString *)tips AutoHideAfterTimer:(CGFloat)showTime{

    
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    if (!tips) return;

    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:window animated:YES];
    hud.detailsLabelText = tips;
    hud.detailsLabelFont= [UIFont systemFontOfSize:15];
    hud.mode = MBProgressHUDModeCustomView;
    hud.removeFromSuperViewOnHide = YES;
    hud.backgroundColor = [UIColor colorWithWhite:0.f alpha:.2f];
    
//    hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;
//    hud.backgroundView.color = [UIColor colorWithWhite:0.f alpha:.2f];
    [hud hide:YES afterDelay:showTime];
//    [hud hideAnimated:YES afterDelay:showTime];
    

}

//显示加载菊花
- (void)showHUD{

    [MBProgressHUD showHUDAddedTo:self animated:YES];

}

//隐藏加载菊花
- (void)hideHUD{

    [MBProgressHUD hideHUDForView:self animated:YES];
}
@end
